package com.unnamed.b.atv.sample.slice;

import com.unnamed.b.atv.sample.ResourceTable;
import com.unnamed.b.atv.sample.ability.TwoDScrollingAbility;
import com.unnamed.b.atv.sample.ability.FolderStructureAbility;
import com.unnamed.b.atv.sample.ability.TwoDScrollingArrowExpandAbility;
import com.unnamed.b.atv.sample.ability.CustomViewHolderAbility;
import com.unnamed.b.atv.sample.ability.SelectableTreeAbility;
import com.unnamed.b.atv.sample.provider.SimpleProvider;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.ListContainer;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * MainAbilitySlice
 *
 * @author Administrator
 * @Date 2021/5/26
 */
public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        final LinkedHashMap<String, Class<?>> listItems = new LinkedHashMap<>();
        listItems.put("Folder Structure Example", FolderStructureAbility.class);
        listItems.put("Custom Holder Example", CustomViewHolderAbility.class);
        listItems.put("Selectable Nodes", SelectableTreeAbility.class);
        listItems.put("2d scrolling", TwoDScrollingAbility.class);
        listItems.put("Expand with arrow only", TwoDScrollingArrowExpandAbility.class);
        final List<String> list = new ArrayList(listItems.keySet());
        ListContainer listview = (ListContainer) findComponentById(ResourceTable.Id_listview);
        SimpleProvider simpleProvider = new SimpleProvider(list , this);
        listview.setItemProvider(simpleProvider);
        listview.setItemClickedListener(new ListContainer.ItemClickedListener() {
            @Override
            public void onItemClicked(ListContainer listContainer, Component component, int i, long l) {
                Class<?> clazz = listItems.values().toArray(new Class<?>[]{})[i];
                Intent intent = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.unnamed.b.atv.sample")
                        .withAbilityName(clazz.getCanonicalName())
                        .build();
                intent.setOperation(operation);
                startAbility(intent);
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

}
